package kit.edu.lego.gruppe3.levels.treeArea.old;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.actions.Movement;
import kit.edu.lego.gruppe3.actions.Orientation;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.sensors.GroundType;
import kit.edu.lego.gruppe3.sensors.Scanner;
import lejos.robotics.subsumption.Behavior;

public class RightTreeHitter implements Behavior {

	private double length = ComponentsRepository.VEHICLE_LENGTH;

	@Override
	public void action() {
		Movement.turnCenter(90);
		Orientation.orientAtWall();
		Movement.turnCenter(-90);
		do {
			while (Scanner.getRangeAt(90, true) < 30)
				Movement.travel(1, 5);
			Movement.travel(length, 10);
			Movement.turnCenter(90);
			Movement.travel(length, 10);
		} while (Scanner.getRangeAt(90, true) < 30);
		Movement.turnCenter(90);
		Movement.travel(length, 10);
		if (Scanner.getRangeAt(-90, true) >= 30
				|| Scanner.getRangeAt(90, true) >= 30)
			TreeAreaSolver.setStatus(TreeAreaState.searchForCorner);
		TreeAreaSolver.setStatus(TreeAreaState.searchForExit);
	}

	@Override
	public void suppress() {
	}

	@Override
	public boolean takeControl() {
		return Level.treeArea == LevelSelector.getInstance().getCurrentLevel()
				&& TreeAreaState.treeFoundRight == TreeAreaSolver.getStatus();
	}

}